package com.ex.common;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * @descrption exception工具类
 * @Author longdeng
 * @Date 2020/8/17 0017 22:35
 */
public class ExceptionUtil {

    /**
     * id生成器 = 时间戳+随机6位数字
     *
     * @param num 随机数字的位数
     * @return
     */
    public static String idCreate(int num) {
        if (num <= 0) {
            throw new RuntimeException("在classs[ExceptionUtil]method[idCreate]的存在异常,参数[num]应该大于0,当前num=" + num);
        }
        String numStr = "0123456789";
        Date date = new Date();
        DateFormat dateFormat = new SimpleDateFormat("yyyymmddHHmmss");
        String dateStr = dateFormat.format(date);
        for (int i = 0; i < num; i++) {
            dateStr += numStr.charAt(new Random().nextInt(numStr.length()));
        }
        return dateStr;
    }


}
